home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / POLYGON.H < prev    next >
Text File  |  1991-10-01  |  3KB  |  73 lines

  1. /* POLYGON.H: Header file for polygon-filling code, also includes
  2.    a number of useful items for 3D animation. */
  3.  
  4. #define MAX_POLY_LENGTH 4  /* four vertices is the max per poly */
  5. #define SCREEN_WIDTH 320
  6. #define SCREEN_HEIGHT 240
  7. #define PAGE0_START_OFFSET 0
  8. #define PAGE1_START_OFFSET (((long)SCREEN_HEIGHT*SCREEN_WIDTH)/4)
  9. /* Ratio: distance from viewpoint to projection plane / width of
  10.    projection plane. Defines the width of the field of view. Lower
  11.    absolute values = wider fields of view; higher values = narrower */
  12. #define PROJECTION_RATIO   -2.0 /* negative because visible Z
  13.                                    coordinates are negative */
  14. /* Draws the polygon described by the point list PointList in color
  15.    Color with all vertices offset by (X,Y) */
  16. #define DRAW_POLYGON(PointList,NumPoints,Color,X,Y)         \
  17.    Polygon.Length = NumPoints;                              \
  18.    Polygon.PointPtr = PointList;                            \
  19.    FillConvexPolygon(&Polygon, Color, X, Y);
  20.  
  21. /* Describes a single 2D point */
  22. struct Point {
  23.    int X;   /* X coordinate */
  24.    int Y;   /* Y coordinate */
  25. };
  26. /* Describes a single 3D point in homogeneous coordinates */
  27. struct Point3 {
  28.    double X;   /* X coordinate */
  29.    double Y;   /* Y coordinate */
  30.    double Z;   /* Z coordinate */
  31.    double W;
  32. };
  33. /* Describes a series of points (used to store a list of vertices that
  34.    describe a polygon; each vertex is assumed to connect to the two
  35.    adjacent vertices, and the last vertex is assumed to connect to the
  36.    first) */
  37. struct PointListHeader {
  38.    int Length;                /* # of points */
  39.    struct Point * PointPtr;   /* pointer to list of points */
  40. };
  41.  
  42. /* Describes the beginning and ending X coordinates of a single
  43.    horizontal line */
  44. struct HLine {
  45.    int XStart; /* X coordinate of leftmost pixel in line */
  46.    int XEnd;   /* X coordinate of rightmost pixel in line */
  47. };
  48.  
  49. /* Describes a Length-long series of horizontal lines, all assumed to
  50.    be on contiguous scan lines starting at YStart and proceeding
  51.    downward (used to describe a scan-converted polygon to the
  52.    low-level hardware-dependent drawing code) */
  53. struct HLineList {
  54.    int Length;                /* # of horizontal lines */
  55.    int YStart;                /* Y coordinate of topmost line */
  56.    struct HLine * HLinePtr;   /* pointer to list of horz lines */
  57. };
  58. struct Rect { int Left, Top, Right, Bottom; };
  59.  
  60. extern void XformVec(double Xform[4][4], double * SourceVec,
  61.    double * DestVec);
  62. extern void ConcatXforms(double SourceXform1[4][4],
  63.    double SourceXform2[4][4], double DestXform[4][4]);
  64. extern void XformAndProjectPoly(double Xform[4][4],
  65.    struct Point3 * Poly, int PolyLength, int Color);
  66. extern int FillConvexPolygon(struct PointListHeader *, int, int, int);
  67. extern void Set320x240Mode(void);
  68. extern void ShowPage(unsigned int StartOffset);
  69. extern void FillRectangleX(int StartX, int StartY, int EndX,
  70.    int EndY, unsigned int PageBase, int Color);
  71. extern int DisplayedPage, NonDisplayedPage;
  72. extern struct Rect EraseRect[];
  73.